<?php

namespace App\Admin\Controllers;

use App\Admin\Extensions\Tools\Back;
use App\Models\CourseLesson;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CourseLessonController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'CourseLesson';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new CourseLesson());
        $grid->column('id', __('Id'));
        $grid->column('title', __('课时标题'));
        $grid->column('type', __('课时类型'))->use(CourseLesson::$typeMap);
        $grid->column('status', __('状态'))->use(CourseLesson::$statusMap);
        $grid->tools(function ($tools) {
            $tools->append(new Back());
        });

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(CourseLesson::findOrFail($id));
        $show->field('id', __('Id'));
        $show->field('title', __('课时标题'));
        $show->field('type', __('课时类型'))->use(CourseLesson::$typeMap);
        $show->field('content', __('课时内容'));
        $show->field('lesson_file', __('课时文件'));
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at')); 
        $show->field('sort', __('排序'));
        $show->field('status', __('状态'))->use(CourseLesson::$statusMap);


        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new CourseLesson());

        $form->text('title', __('课时标题'));
        $form->select('type', __('课时类型'))->options(CourseLesson::$typeMap);
        $form->textarea('content', __('课时内容'));
        $form->file('lesson_file', __('课时文件'));
        $form->multipleFile('extends', __('扩展文件'));
        $form->number('sort', __('排序'));
        $form->radio('status', __('状态'))->options(CourseLesson::$statusMap);
        return $form;
    }
}
